/********************************************************/
/*	Author:		gong_libin			*/
/*	Date:		2017_11_01			*/
/*	File:		CmLogger.cpp			*/
/********************************************************/

#include "CmLogger.h"

CMSTR_C CCmLogger::CmLoggerSerialize()
{
	Json::Value CJsn;
	const char* pszLog[] = CM_ADF_TLOG;
	const char** ppszLog = &pszLog[0];

	CJsn[*ppszLog ++] = m_stLog.m_CMsgId;
	CJsn[*ppszLog ++] = m_stLog.m_ulMsgTim;
	CJsn[*ppszLog ++] = m_stLog.m_uiMsgType;
	CJsn[*ppszLog ++] = m_stLog.m_CDid;
	CJsn[*ppszLog ++] = m_stLog.m_CAid;
	CJsn[*ppszLog ++] = m_stLog.m_CEid;
	CJsn[*ppszLog ++] = m_stLog.m_CCid;
	CJsn[*ppszLog ++] = m_stLog.m_CIP;
	CJsn[*ppszLog ++] = m_stLog.m_CUa;
	CJsn[*ppszLog ++] = m_stLog.m_CUid;
	CJsn[*ppszLog ++] = m_stLog.m_CImei;
	CJsn[*ppszLog ++] = m_stLog.m_CAdvId;
	CJsn[*ppszLog ++] = m_stLog.m_CCrtId;
	CJsn[*ppszLog ++] = m_stLog.m_uiAdvType;
	CJsn[*ppszLog ++] = m_stLog.m_uiAdvSource;
	CJsn[*ppszLog ++] = m_stLog.m_uiAdvPrice;
	CJsn[*ppszLog ++] = m_stLog.m_CAdCtxtId;
	CJsn[*ppszLog ++] = m_stLog.m_uiAdvResCode;
	CJsn[*ppszLog ++] = m_stLog.m_uiAdvBidMeth;

	return CJsn.toStyledString();
}

void CCmLogger::CmLoggerSetMsgType(UINT uiType)
{
	m_stLog.m_uiMsgType = uiType;

	return;
}

void CCmLogger::CmLoggerSetDspId(UINT uiDsp)
{
	m_stLog.m_uiAdvSource = uiDsp;

	return;
}

void CCmLogger::CmLoggerSetResCode(UINT uiCode)
{
	m_stLog.m_uiAdvResCode = uiCode;

	return;
}

CMSTR_C CCmLogger::CmLoggerUuid()
{
	uuid_t iUuid;
	char szUuid[CM_BYTE64] = {'\0'};
 
	uuid_generate(iUuid);
	uuid_unparse(iUuid, szUuid);

	return CMSTR_C(szUuid);
}

ULONG CCmLogger::CmLoggerMillisecond()
{
	struct timeval stTime;
	gettimeofday(&stTime, NULL);

	return stTime.tv_sec * 1000 + stTime.tv_usec / 1000;
}
